<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商品列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>商品编码：</label>
                                <input type="text" name="productCode"/>
                            </li>
                            <li>
                                <label>商品名称：</label>
                                <input type="text" name="productName"/>
                            </li>
                            <li>
                                <label>分类：</label>
                                <input type="text" name="categoryId"/>
                            </li>
                            <li>
                                <label>品牌：</label>
                                <input type="text" name="brandId"/>
                            </li>
                            <li>
                                <label>是否上架：</label>
                                <select name="isPutaway" th:with="type=${@dict.getType('pro_product_is_putaway')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否新品：</label>
                                <select name="isNew" th:with="type=${@dict.getType('pro_product_is_new')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>是否推荐：</label>
                                <select name="isRecommend" th:with="type=${@dict.getType('pro_product_is_recommend')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" th:with="type=${@dict.getType('pro_product_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="product:product:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="product:product:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="product:product:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="product:product:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var listFlag = [[${@permission.hasPermi('product:image:list')}]];
        var editFlag = [[${@permission.hasPermi('product:product:edit')}]];
        var removeFlag = [[${@permission.hasPermi('product:product:remove')}]];
        var codeFlag = [[${@permission.hasPermi('product:product:sku')}]];
        var isPutawayDatas = [[${@dict.getType('pro_product_is_putaway')}]];
        var isNewDatas = [[${@dict.getType('pro_product_is_new')}]];
        var isRecommendDatas = [[${@dict.getType('pro_product_is_recommend')}]];
        var statusDatas = [[${@dict.getType('pro_product_status')}]];
        var prefix = ctx + "product/product";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "商品",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'productId', 
                    title: '商品id',
                    visible: false
                },
                {
                    field: 'productCode', 
                    title: '商品编码'
                },
                {
                    field: 'productName', 
                    title: '商品名称'
                },
                {
                    field: 'retailPrice', 
                    title: '零售价'
                },
                {
                    field: 'currentPrice', 
                    title: '实售价'
                },
                {
                    field: 'categoryName',
                    title: '分类'
                },
                {
                    field: 'brandName',
                    title: '品牌'
                },
                {
                    field: 'typeName',
                    title: '商品类型'
                },
                {
                    field: 'isPutaway', 
                    title: '上架',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isPutawayDatas, value);
                    }
                },
                {
                    field: 'isNew', 
                    title: '新品',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isNewDatas, value);
                    }
                },
                {
                    field: 'isRecommend',
                    title: '推荐',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isRecommendDatas, value);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                        actions.push('<a class="btn btn-info btn-xs  ' + listFlag + '" href="javascript:void(0)" onclick="imageDetail(\'' + row.productId + '\')"><i class="fa fa-edit"></i>图片列表</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.productId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.productId + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + codeFlag + '" href="javascript:void(0)" onclick="genSku(\'' + row.productId + '\')"><i class="fa fa-bug"></i>生成SKU</a> ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        function genSku(productId) {
            var url = prefix + '/genSku/' + productId;
            $.modal.open("生成SKU", url);
        }
        
        function imageDetail(productId) {
            var url = prefix + '/image/detail/' + productId;
            $.modal.openTab("商品图片", url);
        }

    </script>
</body>
</html>